<?php
namespace app\daifast\controller;
use \think\Db;
use think\Session;


class System extends \think\Controller
{ 
    
    /**
     * 系统配置
     */
    public function config(){
        if(input('sbt')){
            model('System')->saveConfig();
            $this->showMsg("配置成功", url('System/config'));
        }
        input('sbt') or $sysConfig = getConfig(); 
        
        return $this->allFetch(get_defined_vars());
    }
    
    
    /**
     * 登录日志
     */
    public function log(){
        $username = addslashes(input('username'));
        $where = " 1=1 ";
        $username and $where .=" and username = '".$username."'"; 
        $data = Db('sys_admin_log')->where($where)->order("id desc")->paginate(10,["query"=>["username"=>$username]]); 
        $listArr = $data->items();
        $pages = $data->render(); 
        
        return $this->allFetch(get_defined_vars());
    }
    
    /**
     * 修改自己密码
     */
    public function repwd(){
       
        if(input('sbt')){
            //数据检测
            $adminInfo  = Session::get('admin');
            $adminInfo['password']!=md5(input('oldPass')) and $this->showMsg("您输入的原始密码错误", url('System/repwd'),'warning');
            input('newPass')!=input('newPass2') and $this->showMsg("您两次输入的密码不一样", url('System/repwd'),'warning');
            //修改密码
            Db('sys_admin')->where('id', $adminInfo['id'])->update(['password'=>md5(input('newPass'))]);
           
            $this->showMsg("修改密码成功", url('Index/login'));
            
            
        }
        
        
        return $this->allFetch(get_defined_vars());
    }
    
    
    /**
     * 修改用户密码
     */
    public function userRepwd(){
        $id = input('id');
        if(input('ajax')){
            
            Db('sys_admin')->where('id', $id)->update(['password'=>md5(input('newpass'))]);
            echojson('ok',1);die;
        }
        
        
        return $this->allFetch(get_defined_vars());
    }
    
    
    
    
}
